﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DualControl.Controllers;
using DualControl.CycleCheckTasks;
using DualControl.CycleCheckTasks.Dtos;
using Microsoft.AspNetCore.Mvc;
using X.PagedList;

namespace DualControl.Web.Mvc.Controllers
{
    public class CycleCheckTaskController : DualControlControllerBase
    {
        private readonly ICycleCheckTaskAppService _cycleCheckTaskAppService;

        public CycleCheckTaskController(ICycleCheckTaskAppService cycleCheckTaskAppService)
        {
            _cycleCheckTaskAppService = cycleCheckTaskAppService;
        }
        public async Task<IActionResult> Index(int page, string view)
        {
            int pagenumber = page < 1 ? 1 : page;
            GetCycleCheckTasksInput input = new GetCycleCheckTasksInput
            {
                SkipCount = (pagenumber - 1) * AppConsts.DefaultPageSize,
                MaxResultCount = AppConsts.DefaultPageSize,
                Sorting= "EndTime"
            };
            //var result = await _hazardSourceAppService.GetPagedHazardSources(input);
            var result = await _cycleCheckTaskAppService.GetPageCycleCheckTaskWithDapper(input);


            var PageOfCycleCheckTaskListDto = new StaticPagedList<CycleCheckTaskListDto>(result.Items, pagenumber, AppConsts.DefaultPageSize, result.TotalCount);
            //将分页结果放入ViewBag供View使用
            ViewBag.PageOfCycleCheckTaskListDto = PageOfCycleCheckTaskListDto;
            return View(view);
        }


        public PartialViewResult CycleCheckModal()
        {
            return PartialView("_CycleCheckModal");
        }
    }
}